<template lang="">
  <!-- 结构内容 -->
  <el-row type="flex" justify="space-between" align="middle" style="height: 40px; width: 100%;">
    <!-- 部门名字 -->
    <el-col>
      <i v-if="isRoot" class="el-icon-s-home" />
      <span>{{ treeData.name }}</span>
    </el-col>
    <el-col :span="4">
      <el-row type="flex" justify="end">
        <el-col style=" width: 100%; overflow: hidden;">{{treeData.manager}}</el-col>
        <el-col>
          <!-- 下拉菜单 element -->
          <el-dropdown trigger="click">
            <span> 操作<i class="el-icon-arrow-down" /> </span>
            <!-- 下拉菜单 -->
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item @click.native="add(treeData)">添加子部门</el-dropdown-item>
              <el-dropdown-item v-if="!isRoot" @click.native="edit(treeData)">编辑部门</el-dropdown-item>
              <el-dropdown-item v-if="!isRoot && !treeData.children" @click.native="del(treeData.id)"
                disabled="!checkPermission('point-user-delete')">删除部门</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-col>
      </el-row>
    </el-col>
  </el-row>
</template>
<script>
  import mixin from '@/mixin/checkPermission.js'
  import { deleteDepartmentAPI, updateDepartmentAPI } from '@/api'
  export default {
    mixins: [mixin],
    props: {
      treeData: {
        required: true
      },
      isRoot: {
        type: Boolean,
        default: false
      }
    },
    methods: {
      // 添加部门
      add (treeData) {
        this.$emit('addDepm', treeData)
      },
      edit (treeData) {
        this.$emit('updateDepm', treeData)
      },
      // 删除部门
      async del (id) {
        const delRes = await this.$confirm('是否删除此部门?', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'waring'
        }).catch(err => err)
        // 说明点击了取消
        if (delRes === 'cancel') return this.$message.success('已取消删除')
        const ai = await deleteDepartmentAPI(id)
        this.$message.success('删除成功')
        this.$emit('delDpm')
      }
    },
  }
</script>
<style lang="">

</style>